<!DOCTYPE HTML>
<html>
<head>
    <title>Todo</title>
    <link rel="stylesheet" href="/stylesheets/style.css">
    <script src="/scripts/jquery.min.js"></script>
    <link rel="stylesheet" href="/scripts/miniui/themes/default/miniui.css">
    <link rel="stylesheet" href="/scripts/miniui/themes/icons.css">
    <link rel="stylesheet" href="/editor/common.css">
    <link rel="stylesheet" href="/scripts/miniui/themes/bootstrap/skin.css">
    <script src="/scripts/miniui/miniui.js"></script>
</head>
<body style="width:80% ;height: 80%;">
<div style="width:100%;height:100%;">
    <div style="padding: 5px">
        <span>部落名：</span><input class="mini-textbox" type="text" id="name"/>
        <a class="mini-button" iconCls="icon-search" onclick="search()">查找</a>
    </div>

    <div i id="datagrid1" class="mini-datagrid" style="width:99%;height: 82%;" multiSelect="true" ;
         url="/getData/liveCopy"
         idField="id" allowResize="true"
         sizeList="[20,30,50,100]" pageSize="30"
    >
        <div property="columns">
            <div type="checkcolumn"></div>
            <div field="name" width="100" align="center" align="left" headerAlign="center">部落名</div>
        </div>
    </div>

</div>
<div style="text-align: center">
    <a class="mini-button " iconCls="icon-ok" onclick="changeTitle()">确定</a>
    <a class="mini-button" iconCls="icon-cancel" onclick="onCancel()">取消</a>
</div>
</body>
<script type="text/javascript">
    var liveObjectId = '<%- liveObjectId %>'
    mini.parse();
    var grid = mini.get("datagrid1");
    grid.load();

    function search() {
        let name = mini.get('name').getValue();
        grid.load({name})
    }

    function changeTitle() {
        let rows = grid.getSelecteds();
        if (rows) {
            let tribeList = [];
            for (row of rows) {
                let tribeOId = row.objectId;
                tribeList.push(tribeOId);
            }

            $.ajax({
                type: "POST",
                url: "/getdata/addTribeLive",
                data: {
                    tribeList: tribeList,
                    liveObjectId
                },
                success: function (result) {
                    if (result == 1) {
                        CloseWindow("save");
                        alert("复制成功")
                    } else {
                        alert("更改失败");
                        CloseWindow("save");
                    }

                }
            })
        }
    }

    //    关闭窗口
    function CloseWindow(action) {
        if (action == "close" && form.isChanged()) {
            if (confirm("数据被修改了，是否先保存？")) {
                return false;
            }
        }
        if (window.CloseOwnerWindow) return window.CloseOwnerWindow(action);
        else
            window.close();
    }

    function onCancel(e) {
        CloseWindow("cancel");
    }
</script>
</html>